package com.klb.dao.impl;


import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.klb.base.DaoBase;
import com.klb.dao.BlockDao;
import com.klb.model.BbsBlock;
import com.klb.tools.Tools;

/**
 * Created by fujia on 2016/6/2.
 */
public class BlockDaoImpl extends DaoBase implements BlockDao {


    @Override
    public BbsBlock getBlockById(int blockId) {
    	BbsBlock block = null;
    	
        if (!Tools.objectIsNullOrNot(blockId)){
            Session session = this.hibernateSessionFactory.getCurrentSession();
            Transaction tx = null;
            String sql = "from BbsBlock block where block.blockId = :blockId";


            try {
                tx = session.beginTransaction();

                Query query = session.createQuery(sql);
                query.setParameter("blockId", blockId);

                block = (BbsBlock) query.uniqueResult();

                tx.commit();

            }catch (Exception e){
                tx.rollback();
                e.printStackTrace();
            }

        }

        return block;
    }
}
